
<?php 
session_start();
if (!isset($_SESSION['uname'])){ echo"login required";}
include("sql.php");
include("config.php");
$aq= retaq();
if (!isset($_POST['qno'])){die("qno not set");}
else { if ( $_POST['qno']!=$aq){ echo"q changed"; exit(0); } }
if(isset($_POST['code'])){
$content=$_POST['code'];
if (strlen($content)>$maxsize){die("file to lorge");}
$tim=time();
$filename="submit\\$tim.cpp";
$fh = fopen($filename, 'w') or die("can't open file");
fwrite($fh,$content);
fclose($fh);
//$query="bcc32 -nsubmit $filename >submit\c$tim.txt";
$query2="bcc32 -nsubmit $filename";
//pclose(popen("start /B ". $query, "r"));
exec($query2,$output,$ret);
foreach ($output as $out)
{echo "<br>$out";
}
flush(); ob_flush();

//echo "$ret";
if ($ret==0){
$qdat=getq();
$query3="submit\\$tim.exe >submit\\o$tim.txt < testcases\\$qdat[2] ";
//$query3="submit\\$tim.exe <testcases\1.txt";
//echo "<br>$query3";
echo " <br> running compiled program <br>";
exec($query3,$output2);
foreach ($output2 as $out1)
{echo "<br>$out1";}
//pclose(popen("start /B ". $query3, "r"));
while ( $tim +10 > time()){}
exec("taskkill /F /IM $tim.exe",$output2,$rk);
if ($rk==0){foreach ($output2 as $out1)
{echo "<br>$out1 <b> program excedded runtime </b>";}}
$queryx= "comp answers\\$qdat[2] submit\\o$tim.txt /A /L < comp.txt";
echo"<br> $queryx";
exec($queryx,$output2,$retc);
if ($retc==0){echo "<BR><BR><b>CORRECT</b>"; updateall();}
else {foreach ($output2 as $out1)
{echo "<br>$out1";}}

}
}
?>